#include"comm.hpp"

using namespace std;

int main()
{
    int shmid = shmget(ftok(FILE_PATH, NUM), SIZE, IPC_CREAT | IPC_EXCL | 0666);

    if(shmid < 0)
    {
        perror("shmget");
        exit(SHMGET_ERR);
    }

    cout << "共享内存创建完毕，shmid：" << shmid << endl;

    char* shmadd = (char*)shmat(shmid, nullptr, 0);

    cout << "挂接完成" << endl;

    // sleep(10);

    // char buffer[1024] = {0};
    while(1)
    {
        // buffer[0] = 0;
        fgets(shmadd, 1024, stdin);
        // memcpy(shmadd, buffer, strlen(buffer) + 1);
        if(strcmp(shmadd, "exit\n") == 0)
        {
            break;
        }
    }

    shmdt(shmadd);

    cout << "去关联成功" << endl;

    shmctl(shmid, IPC_RMID, nullptr);

    cout << "标记删除成功" << endl;

    return 0;
}